<?php

namespace App\Http\Requests\Strator;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateStratorRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'id'=>'required|integer|min:0',
            'strator_account'=>[
                'required',
                'alpha_num',
                'min:6',
                'max:30',
                Rule::unique('strators','strator_account')->ignore($this->id??0),
            ],
            'strator_mobile'=>[
                'sometimes',
                'integer',
                'min:10000000000',
                'max:19999999999',
                Rule::unique('strators','strator_mobile')->ignore($this->id??0),
            ],
            'strator_email'=>[
                'sometimes',
                'email',
                Rule::unique('strators','strator_email')->ignore($this->id??0),
            ],
            'strator_password'=>'sometimes|string|min:8|max:20',
        ];
    }
    /**
     * Get the error messages for the defined validation rules.
     *
     * @return array<string, string>
     */
    public function messages(): array
    {
        return [
            'id.required'=>'id参数为必传',
            'id.integer'=>'id参数错误',
            'id.min'=>'id参数错误',

            'strator_account.required' => '账号为必填',
            'strator_account.alpha_num' => '账号只能包含字母和数字',
            'strator_account.min' => '账号长度要在6-30位之间',
            'strator_account.max' => '账号长度要在6-30位之间',
            'strator_account.unique' => '账号已存在',

            'strator_mobile.integer' => '手机号格式不正确',
            'strator_mobile.min' => '手机号格式不正确',
            'strator_mobile.max' => '手机号格式不正确',
            'strator_mobile.unique' => '此手机号已存在',

            'strator_email.email' => '邮箱格式不正确',
            'strator_email.unique' => '此邮箱已存在',

            'strator_password.string' => '密码必须为字符串类型',
            'strator_password.min' => '密码长度要在8-20位之间',
            'strator_password.max' => '密码长度要在8-20位之间',
        ];
    }


}
